<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Log Class - Fuel Documentation</title>
	<link href="../assets/css/main.css" media="screen" rel="stylesheet" />
	<script type="text/javascript" src="../assets/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="../assets/js/nav.js"></script>
	<script type="text/javascript" src="../assets/js/highlight.pack.js"></script>
	<script type="text/javascript">
		$(function() {
			show_nav('classes', '../');
		});
		hljs.tabReplace = '    ';
		hljs.initHighlightingOnLoad();
	</script>
</head>
<body>

	<header>
		<h1>Fuel Documentation</h1>
	</header>

	<div id="main-nav"></div>

	<section id="content">
		<h2>Log Class</h2>

		<p>The log class allows you to write messages to the log files.</p>

		<h5>Configuration</h5>

		<p>The log files are being placed in the folder specified by the attribute '<strong>log_path</strong>' in the <strong>config.php</strong>. You can also set the '<strong>log_threshold</strong>' and the '<strong>log_date_format</strong>' parameters there.<br/>These settings can also be changed on the fly by using the <a href="config.html">Config Class</a>.</p>

		<table class="config">
			<tbody>
				<tr class="header">
					<th>Param</th>
					<th>Type</th>
					<th>Default</th>
					<th>Description</th>
				</tr>
				<tr>
					<th>log_threshold</th>
					<td>constant</td>
					<td><pre class="php"><code>Fuel::L_ERROR</code></pre></td>
					<td>
						Can be any of the following: <code>Fuel::L_NONE, Fuel::L_ERROR, Fuel::L_DEBUG, Fuel::L_INFO or Fuel::L_ALL</code>
					</td>
				</tr>
				<tr>
					<th>log_path</th>
					<td>string</td>
					<td><pre class="php"><code>APPPATH.'logs/'</code></pre></td>
					<td>
						Where to put the log files. (Folder must be writable)
					</td>
				</tr>
				<tr>
					<th>log_date_format</th>
					<td>string</td>
					<td><pre class="php"><code>'Y-m-d H:i:s'</code></pre></td>
					<td>
						The date format for the log entries. This format must follow the PHP date format rules. See <a href="http://www.php.net/date">http://www.php.net/date</a> for a complete list.
					</td>
				</tr>
			</tbody>
		</table>

		<h5>Usage</h5>
		
		<p>There are three predefined functions for ease of use:</p>
		<pre class="php"><code>Log::info()
Log::debug()
Log::error()</code></pre>
		
		<p>They all use the main function <strong>Log::write()</strong> which requires the <strong>$level</strong> parameter as the first argument.</p>
		
		<h6>Some examples:</h6>
		<pre class="php"><code>// Write a log entry with the level "Info" to the log file for the current day
$var = 1;
Log::info('Application started (with $var = '.$var.')', 'my_init_function()');

// Save the new value of $var to the log file, without the $method parameter
$var = 5;
Log::debug('$var is now '.$var);

// Send an error log entry
if($var !== 1) Log::error('We cannot keep going, $var has been changed! :o');

// Finally, create a log entry with a custom $level
Log::write('Link', 'More info on http://fuelphp.com/');</code></pre>
		
		<h5>Output</h5>
		
		<p>All log files are being placed in the defined folder (see above), composed in folders named by the current <strong>year</strong> followed by the <strong>month</strong> (<em>"2011/06"</em> for example) with the day of the month as the filename (<em>"15.php"</em> for example).<br/>The complete path to our example log file would be: <strong>APPPATH.'logs/2011/06/15.php'</strong></p>

		<p><strong>The examples above would write the following code to the log file:</strong>
		<pre class="php"><code>&lt;?php defined('COREPATH') or exit('No direct script access allowed'); ?&gt;<br/><br/>Info - 2011-01-03 18:44:45 --> my_init_function() - Application started (with $var = 1)<br/>Debug - 2011-01-03 18:44:45 --> $var is now 5<br/>Error - 2011-01-03 18:44:45 --> We cannot keep going, $var has been changed! :o<br/>Link - 2011-01-03 18:44:45 --> More info on http://fuelphp.com/</code></pre>

		<article>
			<h4>info($msg, $method = null)</h4>
			<p>The <strong>info</strong> method allows you to write a log entry with the <strong>$level</strong> "Info".</p>
			<table class="method">
				<tbody>
				<tr>
					<th class="legend">Static</th>
					<td>Yes</td>
				</tr>
				<tr>
					<th>Parameters</th>
					<td>
						<table class="parameters">
							<tr>
								<th>Param</th>
								<th>Default</th>
								<th class="description">Description</th>
							</tr>
							<tr>
								<th><kbd>$msg</kbd></th>
								<td><i>required</i></td>
								<td>The message for the info log entry.</td>
							</tr>
							<tr>
								<th><kbd>$method</kbd></th>
								<td><pre class="php"><code>null</code></pre></td>
								<td>Information about the method which created the log entry.</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<th>Returns</th>
					<td>boolean</td>
				</tr>
				<tr>
					<th>Example</th>
					<td>
						<pre class="php"><code>$var = 1;<br/>Log::info('Application started (with $var = '.$var.')', 'my_init_function()');</code></pre>
					</td>
				</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4>debug($msg, $method = null)</h4>
			<p>The <strong>debug</strong> method allows you to write a log entry with the <strong>$level</strong> "Debug".</p>
			<table class="method">
				<tbody>
				<tr>
					<th class="legend">Static</th>
					<td>Yes</td>
				</tr>
				<tr>
					<th>Parameters</th>
					<td>
						<table class="parameters">
							<tr>
								<th>Param</th>
								<th>Default</th>
								<th class="description">Description</th>
							</tr>
							<tr>
								<th><kbd>$msg</kbd></th>
								<td><i>required</i></td>
								<td>The message for the info log entry.</td>
							</tr>
							<tr>
								<th><kbd>$method</kbd></th>
								<td><pre class="php"><code>null</code></pre></td>
								<td>Information about the method which created the log entry.</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<th>Returns</th>
					<td>boolean</td>
				</tr>
				<tr>
					<th>Example</th>
					<td>
						<pre class="php"><code>$var = 5;<br/>Log::debug('$var is now '.$var);</code></pre>
					</td>
				</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4>error($msg, $method = null)</h4>
			<p>The <strong>error</strong> method allows you to write a log entry with the <strong>$level</strong> "Error".</p>
			<table class="method">
				<tbody>
				<tr>
					<th class="legend">Static</th>
					<td>Yes</td>
				</tr>
				<tr>
					<th>Parameters</th>
					<td>
						<table class="parameters">
							<tr>
								<th>Param</th>
								<th>Default</th>
								<th class="description">Description</th>
							</tr>
							<tr>
								<th><kbd>$msg</kbd></th>
								<td><i>required</i></td>
								<td>The message for the info log entry.</td>
							</tr>
							<tr>
								<th><kbd>$method</kbd></th>
								<td><pre class="php"><code>null</code></pre></td>
								<td>Information about the method which created the log entry.</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<th>Returns</th>
					<td>boolean</td>
				</tr>
				<tr>
					<th>Example</th>
					<td>
						<pre class="php"><code>// we send an error log entry<br/>if($var !== 1) Log::error('We cannot keep going, $var has been changed! :o');</code></pre>
					</td>
				</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4>write($level, $msg, $method = null)</h4>
			<p>The <strong>write</strong> method allows you to write a log entry with a custom <strong>$level</strong>.</p>
			<table class="method">
				<tbody>
				<tr>
					<th class="legend">Static</th>
					<td>Yes</td>
				</tr>
				<tr>
					<th>Parameters</th>
					<td>
						<table class="parameters">
							<tr>
								<th>Param</th>
								<th>Default</th>
								<th class="description">Description</th>
							</tr>
							<tr>
								<th><kbd>$level</kbd></th>
								<td><i>required</i></td>
								<td>A custom Level.</td>
							</tr>
							<tr>
								<th><kbd>$msg</kbd></th>
								<td><i>required</i></td>
								<td>The message for the info log entry.</td>
							</tr>
							<tr>
								<th><kbd>$method</kbd></th>
								<td><pre class="php"><code>null</code></pre></td>
								<td>Information about the method which created the log entry.</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<th>Returns</th>
					<td>boolean</td>
				</tr>
				<tr>
					<th>Example</th>
					<td>
						<pre class="php"><code>// and finally, we create a log entry with a custom $level<br/>Log::write('Link', 'More info on http://fuelphp.com/')</code></pre>
					</td>
				</tr>
				</tbody>
			</table>
		</article>
	</section>

	<section id="footer">
		<p>
			<a href="http://fuelphp.com">Fuel</a> is released under the MIT license.<br />
			&copy; 2010 - 2011 Fuel Development Team
		</p>
	</section>

</body>
</html>
